package com.vcc.web.core.thread;

import com.vcc.core.util.IdWorker;
import com.vcc.core.util.RegexUtil;
import com.vcc.data.entity.ReserveCard;
import com.vcc.web.core.component.PingPongComponent;
import com.vcc.web.core.component.RedisComponent;
import com.vcc.service.service.ReserveCardService;

public class PingPongReserveThread extends Thread {
    private PingPongComponent pingPongComponent;
    private ReserveCardService reserveCardService;
    private RedisComponent redisComponent;
    private Long cardId;
    private String code;
    private int count;

    public PingPongReserveThread() {
    }

    public PingPongReserveThread(PingPongComponent pingPongComponent,
                                 ReserveCardService reserveCardService,
                                 RedisComponent redisComponent,
                                 Long cardId,
                                 String code,
                                 int count) {
        this.pingPongComponent = pingPongComponent;
        this.reserveCardService = reserveCardService;
        this.redisComponent = redisComponent;
        this.cardId = cardId;
        this.code = code;
        this.count = count;
    }

    @Override
    public void run() {
//        for (int i = 0; i < count; i++) {
//            String orderId = IdWorker.getStringOrderId();
//            String ppCardId = pingPongComponent.openCard(code, orderId);
//            //此处忽略异常
//            if (RegexUtil.checkStringIsNotNull(ppCardId)) {
//                ReserveCard reserveCard = new ReserveCard();
//                reserveCard.setCardId(cardId);
//                reserveCard.setCardNumber("");
//                reserveCard.setVcc("");
//                reserveCard.setExpiry("");
//                reserveCard.setPpCardId(ppCardId);
//                reserveCard.setOrderId(orderId);
//                reserveCard.setStatus(2);
//                reserveCardService.save(reserveCard);
//                redisComponent.set(ppCardId + ":Reserve", cardId);
//            }
//        }
    }
}
